<?php

namespace Core\Data\UDD;

class Table {

    private $Document;
    private $Database;
    private $arrFields = array ();
    private $objRecord = null;
    private $arrMethods = array ();

    private $strName;
    private $strPrefix;
    private $objParent;

    function __construct ( Document $objDocument, Database $objDatabase, $strName, $strPrefix ) {
        $this->Document = $objDocument;
        $this->Database = $objDatabase;
        $this->strName = $strName;
        $this->strPrefix = $strPrefix;
    }

    function __toString () {
        return ( $this->getPrefix() ) ? $this->getPrefix() . "_" . $this->getName() : $this->getName();
    }

    public function addField ( $strName, $constDataType = Core_Data_UDD_DataType::TEXT ) {
        $objField = new Field ( $this, $strName, $constDataType );
        $this->arrFields[(string) $objField] = $objField;
        return $objField;
    }

    public function addRecord () {
        $objRecord = new Record ( $this );
        $this->objRecord = $objRecord;
        return $objRecord;
    }

    public function getRecord () {
        return $this->objRecord;
    }

    public function fields () {
        return (object) $this->arrFields;
    }

    public function isField ( $strFieldName ) {
        return ( in_array( $strFieldName, $this->arrFields ) ) ? true : false;
    }

    public function getName () {
        return $this->strName;
    }

    public function getPrefix () {
        return $this->strPrefix;
    }

    public function getParent () {
        return $this->objParent;
    }

    public function setParent ( $objParent ) {
        $this->objParent = $objParent;
    }

}

?>
